#include"Deque.h"

Deque::Deque()
{
	front = 0;
	rear = maxqueue - 1;
}

bool Deque::empty()const
{
	return front == 0 && rear == maxqueue - 1;
}

Error_code Deque::append_front(const Queue_entry& item)
{
	if (front - 1 == rear)
		return overflow;
	entry[front++] = item;
	return success;
}

Error_code Deque::append_rear(const Queue_entry& item)
{
	if (front - 1 == rear)
		return overflow;
	entry[rear--] = item;
	return success;
}

Error_code Deque::serve_front()
{
	if (front < 0)
		return underflow;
	for (int i = 1; i <= front; i++)
	{
		entry[i - 1] = entry[i];
	}
	front--;
	return success;
}

Error_code Deque::serve_rear()
{
	if (rear >= maxqueue)
		return underflow;
	for (int i = maxqueue - 2; i >= rear; i--)
	{
		entry[i + 1] = entry[i];
	}
	rear++;
	return success;
}

Error_code Deque::retrieve_front(Queue_entry& item)const
{
	if (front < 0)
		return underflow;
	item = entry[0];
	return success;
}

Error_code Deque::retrieve_rear(Queue_entry& item)const
{
	if (rear >= maxqueue)
		return underflow;
	item = entry[maxqueue - 1];
	return success;
}